<?php
/*
 *
 * @author Faker
 * @date 2020-12-19 15:38
 */


namespace app\common\controller;


use app\index\model\Lists;
use think\Db;

class ArticalCm
{
    /**
     * 查询字段
     * @param array $cdn
     * @param string $field 查询字段
     * @return mixed
     */
    public function GetField($cdn, $field){
        $field_value = Db::name('article')->where($cdn)->value($field);
        return $field_value;
    }

    /**
     * 查询条件查询
     * @param string $start
     * @param string $limit
     * @param array $cdn
     * @param string $order
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @author LeeBW
     * @date 2020-12-19 15:56
     */
    public function getArticleData($start = '', $limit = '' , $cdn=array(), $order = '')
    {
        $joinSql=Lists::order('create_time desc')->where($cdn)->limit($start, $limit)->buildSql();
        $lists = Db::table($joinSql . 'tem')->select();

        return !empty($lists)? $lists:false;

    }

    /**返回
     * @param $cdn
     * @return int|string
     * @author LeeBW
     * @date 2020-12-19 16:00
     */
    public function getArticleCount($cdn)
    {
        return Lists::where($cdn)->count();
    }

    /**
     * 更新文章的状态
     * @param $id
     * @param $cdn
     * @return int|string
     */
    public static  function updateArticleState($id,$cdn)
    {
        return Lists::where('id',$id)->update($cdn);
    }

}